<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="模型ID" prop="id">
        <el-input
          v-model="queryParams.publishContent"
          placeholder="发表内容"
          clearable
          size="small"
          @input="handleQuery"
        />
      </el-form-item>

      <el-form-item label="上传用户" prop="displayName">
        <el-input
          v-model="queryParams.username"
          placeholder="支持搜索发表用户和被评论的用户"
          clearable
          size="small"
          @input="handleQuery"
        />
      </el-form-item>

      
      <el-form-item label="上传时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

         <el-form-item label="帖子状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

         <el-form-item label="帖子状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      

        

 

      <!-- 
      <el-form-item label="标签" prop="tags">
        <el-select-v2
          v-model="queryParams.tags"
          :options="userTypeTags"
          placeholder="请选择标签"
          multiple
        />
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="Search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div class="layout-content">
      <el-row class="table-header">
        <span>评论</span>
      </el-row>

      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="
          tableData.filter(
            (data) =>
              !search || data.name.toLowerCase().includes(search.toLowerCase())
          )
        "
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
               
        <el-table-column
          label="操作"
          align="left"
          width="100"
        >
          <template #default="scope">
            <el-button
              size="mini"
              type="text"
              @click="Offline(scope.row)"
              >下线</el-button
            >
          </template>
        </el-table-column>

        <el-table-column label="标题" prop="phone" />

  <el-table-column label="发表内容" prop="phone" />

  <el-table-column label="评论数" prop="phone" width="200px" sortable />
    <el-table-column label="用户" prop="phone" width="200px" />
<el-table-column label="状态" prop="phone" width="200px" />
      
        <el-table-column label="发表时间" prop="createTime" sortable>
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.current"
        v-model:limit="queryParams.size"
        @pagination="getList"
      />
    </div>
  </div>
</template>
<script setup name="UserList">
import { listModel, infoModel } from "@/api/model/list";
import { commit } from "@/api/speech/commit";
import { ref } from "vue";
const { proxy } = getCurrentInstance();
const search = ref("");
const total = ref("0");
const loading = ref(true);
const router = useRouter();
const dateRange = ref([]);
const ids = ref([]);
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");

// 搜索栏的显隐
const showSearch = ref(true);




// 获取用户的选中
const multipleSelection = ref("");
const queryParams = reactive({
  current: 1,
  size: 10,
  publishContent: undefined,
  username: undefined,
    title: undefined,
  status: undefined,
});

// 用户数据列表
const tableData = ref([]);
// 获取用户数据列表
function getList() {
  loading.value = true;
  commit(queryParams).then((response) => {
    console.log("response.data", response.data);
    total.value = response.data.total;
    tableData.value = response.data.records;
    loading.value = false;
  });
}


/** 删除按钮操作 */
function Offline(row) {
  const userIds = row.userId || ids.value;
  proxy.$modal.confirm('确定下线该评论嘛？').then(function () {
    return delUser(userIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
};



/** 搜索按钮操作 */
function handleQuery() {
  queryParams.current = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  getList();
}

getList();
</script>
<style lang="scss">

</style>
